#!/bin/bash

clear

zen_nospam() {
  zenity 2> >(grep -v 'Gtk' >&2) "$@"
}

while true; do
    C_PASSWORD=$(zen_nospam --entry --title="password" --text="请输入终端密码:（下次打开时不需要再输入密码）")
    echo
    echo "$C_PASSWORD" | sudo -S -v 2>/dev/null

    # 检查验证结果
    if [[ $? -eq 0 ]]; then
        echo -e "\e[34m密码正确！\e[0m"
        break
    else
        zen_nospam --error --text="密码错误！请重试"
        clear
    fi
done

mkdir -p /home/deck/.cache/plugin_patch_zenity
mkdir -p /home/deck/.local/share/applications

echo "#!/bin/bash
C_PASSWORD=$C_PASSWORD
echo \$C_PASSWORD | sudo -S ls &> /dev/null
sudo rm /home/deck/.cache/plugin_patch_zenity/plugin_patch_zenity.sh
sudo chmod -R 777 /home/deck/.cache/plugin_patch/
wget -P /home/deck/.cache/plugin_patch_zenity/ https://vip.123pan.cn/1824872873/releases/plugin_patch_zenity.sh
chmod +x /home/deck/.cache/plugin_patch_zenity/plugin_patch_zenity.sh
sudo /home/deck/.cache/plugin_patch_zenity/plugin_patch_zenity.sh" > /home/deck/.cache/plugin_patch_zenity/run_ppz.sh

echo "#!/usr/bin/env xdg-open
[Desktop Entry]
GenericName=集超多功能为一体的懒人工具箱
Categories=Utility;
Exec=bash /home/deck/.cache/plugin_patch_zenity/run_ppz.sh
Icon=rosegarden
Name=SteamOS万能工具箱
StartupNotify=true
Terminal=true
Type=Application" > /home/deck/.local/share/applications/plugin_patch_zenity.desktop


cp -rf /home/deck/.local/share/applications/plugin_patch_zenity.desktop /home/deck/Desktop/plugin_patch_zenity.desktop
chmod +x /home/deck/.local/share/applications/plugin_patch_zenity.desktop /home/deck/Desktop/plugin_patch_zenity.desktop /home/deck/.cache/plugin_patch_zenity/run_ppz.sh

echo -e "\e[34m脚本和桌面快捷方式已成功创建\e[0m"
konsole --new-tab -e "bash /home/deck/.cache/plugin_patch_zenity/run_ppz.sh"
